#include <iostream>
#include<map>
#include<string>
using namespace std;
bool prost(int x){
  bool conf = 1;
  for(int i=2; i < x; i++){
    if (x%i==0){
      conf = 0;
      break;
    }
  }
  return conf;
}
int main()
{
    map <string, int> Numbers;
    Numbers["zero"] = 0;
    Numbers["one"] = 1;
    Numbers["two"] = 2;
    Numbers["three"] = 3;
    Numbers["four"] = 4;
    Numbers["five"] = 5;
    Numbers["six"] = 6;
    Numbers["seven"] = 7;
    Numbers["eight"] = 8;
    Numbers["nine"] = 9;

    string a, b, c;
    bool cont = 1;
    cin >> a;
    if(Numbers.count(a) == 0){
        cout << "Wrong input";
        cont = 0;
    }
    else{
        cin >> b;
        if(Numbers.count(b) == 0){
            cout << "Wrong input";
            cont = 0;
    }
        else{
            cin >> c;
            if(Numbers.count(b) == 0){
                cout << "Wrong input";
                cont = 0;
            }
    }
    }
    string zn[3] = {a, b, c};
    if (cont == 1){
        int n = Numbers[zn[0]]*100+Numbers[zn[1]]*10+Numbers[zn[2]];
        for(int y = 0; y < n; y++){
            if (prost(n-y)){
                    cout << n-y;
                    break;
            }
            else if (prost(n+y)){
                    cout << n+y;
                    break;
        }
    }
    }
    return 0;
}